/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public void reorderList(ListNode head) {
        // 找到中间节点 快慢双指针
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        // 逆序后面 头插
        ListNode pHead = new ListNode();
        ListNode cur = slow.next;
        slow.next = null;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = pHead.next;
            pHead.next = cur;
            cur = next;
        }
        //合并 双指针
        ListNode cur1 = head;
        ListNode cur2 = pHead.next;
        ListNode ret = new ListNode();
        ListNode pre = ret;
        while (cur1 != null) {
            pre.next = cur1;
            pre = cur1;
            cur1 = cur1.next;

            if (cur2 != null) {
                pre.next = cur2;
                pre = cur2;
                cur2 = cur2.next;
            }

        }
    }
}